<!---
   Copyright 2011 Andrew Myers

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
--->

<cfcomponent name="CacheObjectWrapper" hint="Wrapper around the object to store in the cache.  Contains metadata to assist with determining whether the object has expired or not.">

	<!---
	PROPERTIES
	--->
	<cfset variables.instance = StructNew() />

	<cffunction name="init" access="public" returntype="CacheObjectWrapper" hint="Constructor.">
		<cfargument name="objVal" type="any" required="false" default="" />
		<cfargument name="expires" type="date" required="false" default="#CreateDate(3999,1,1)#" />
		<cfargument name="createdDate" type="date" required="false" default="#now()#" />
		<cfset setObjVal(arguments.objVal) />
		<cfset setExpires(arguments.expires) />
		<cfset setCreatedDate(arguments.createdDate) />
		<cfreturn this />
	</cffunction>

	<cffunction name="setObjVal" access="public" returntype="void" output="false">
		<cfargument name="objVal" type="any" required="true" />
		<cfset variables.instance.objVal = arguments.objVal />
	</cffunction>
	<cffunction name="getObjVal" access="public" returntype="any" output="false">
		<cfreturn variables.instance.objVal />
	</cffunction>
	
	<!--- We need to handle things here such as - "tomorrow", "daily at 1am", etc --->
	<cffunction name="setExpires" access="public" returntype="void" output="false">
		<cfargument name="expires" type="date" required="true" />
		<cfset variables.instance.expires  = arguments.expires />
	</cffunction>
	<cffunction name="getExpires" access="public" returntype="date" output="false">
		<cfreturn variables.instance.expires />
	</cffunction>	

	<cffunction name="setCreatedDate" access="public" returntype="void" output="false">
		<cfargument name="createdDate" type="date" required="true" />
		<cfset variables.instance.createdDate  = arguments.createdDate />
	</cffunction>
	<cffunction name="getCreatedDate" access="public" returntype="date" output="false">
		<cfreturn variables.instance.createdDate />
	</cffunction>	

	<cffunction name="isExpired" access="public" returntype="boolean" output="false" hint="Return whether or not this object has expired.">
		<cfif DateCompare(now(), variables.instance.expires) lt 0>
			<cfreturn false>
		<cfelse>
			<cfreturn true>
		</cfif>
	</cffunction>	
	
	<cffunction name="isCurrent" access="public" returntype="boolean" output="false" hint="Return whether or not this object is older than the provided date.">
		<cfargument name="compareDate" type="date" required="true" hint="The date with which to compare this object.">
		<cfif DateCompare(variables.instance.createdDate, compareDate) lt 0>
			<cfreturn true>
		<cfelse>
			<cfreturn false>
		</cfif>
	</cffunction>	
	
</cfcomponent>